package com.iss.yunpan.controller;

//<<<<<<< HEAD
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.SessionAttributes;
//
//@SessionAttributes("users")
//@Controller
//public class ShareController{
//    @RequestMapping("share")
//    public  String toShare(){return "file/share";}
//=======
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iss.yunpan.entity.FileContent;
import com.iss.yunpan.service.FileShareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.DataFormatException;

@Controller
public class ShareController {

    @Autowired
    private FileShareService service;

    @RequestMapping("getAllShareFile")
    @ResponseBody
    public Map<String, Object> getAllShareFile(String id, int page, int limit,String parentId){
        System.out.println(id);
        if(parentId==null) {
            parentId = "0";
        }
        Map<String, Object>map=new HashMap<>();
        PageHelper.startPage(page,limit);
        List<FileContent> list=service.getAllShareFile(id);
        PageInfo<FileContent> pageInfo =new PageInfo<FileContent>(list);
        System.out.println(pageInfo);
        map.put("code",0);
        map.put("msg","");
        map.put("count",pageInfo.getTotal());
        map.put("data", pageInfo.getList());
        return map;
    }

    @RequestMapping("cancel")
    @ResponseBody
    public Map<String,Object>cancel(String fileAbsolute)
    {
        Map<String, Object>map=new HashMap<>();

//        TODO obs内容分享取消
        Integer tmp = service.cancel(fileAbsolute);
        if(tmp > 0){
            map.put("code",0);
            map.put("msg","取消此分享成功");
        }else{
            map.put("msg","未知错误，请联系管理员");
        }

        return  map;
    }

    @RequestMapping("edit")
    @ResponseBody
    public Map<String,String>edit(String fileAbsolute, Integer timeRemaining)
    {
        Map<String, String>map=new HashMap<>();

        String url = service.edit(fileAbsolute, timeRemaining);
        map.put("url",url);
        return map;

    }
}